Skip to content

fix(studio): rotating a layer in a sealed preview turns it from the angle its stylesheet shows - #8469

Merged
miguel-heygen merged 5 commits into
mainfrom
oncall/sealed-rotate-stylesheet
Nov 22, 2026
Merged

miguel-heygen merged 5 commits into
mainfrom
oncall/sealed-rotate-stylesheet

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

Rotating a layer in a sealed (opaque-origin) preview now turns it live from the angle it shows, when its turn or
its centring transform comes from a stylesheet rather than an inline style.

Why

In a sealed preview Studio cannot read the frame's element, so it reads a stand-in that carries only the element's
inline styles. A rotate pressed on a layer whose stylesheet sets rotate: 30deg therefore started from 0 and the
frame drew the turn 30 degrees short, and a layer centred with transform: translate(-50%, -50%) turned about the
wrong point. A second fault hid behind the first: the frame's draft validator accepted only the css and gsap
rotate routes, so a turn drawn inside a translating transform was refused and never drawn while dragging.

On the edit-accuracy bench (full grid, rotate cases, three runs per mode) 12 of 124 rotate cases missed in a sealed
preview and none unsealed, the same 12 every run, by 62 to 111 px. With this change, at current main, those 12
cases are accurate in all three sealed runs (12/12 each), and unsealed stays 12/12; the same 12 at main without it
miss sealed again in the control run.

Related work

Follows the sealed rotate work in #8271. Move and nudge in a sealed preview are #8263; resize and move of layers
GSAP holds, scales or spins in a sealed preview still miss and are tracked separately.

How

  • @hyperframes/core/runtime/css-rotation (new export): the CSS turn reader Studio used, moved from Studio so the
    frame and Studio read a plain turn the same way.
  • The frame's gesture-start answer carries cssRotation (the angle shown and where a rotate draws more) when GSAP
    does not own the element's turn; Studio uses it for a stand-in and still reads a scriptable element directly.
  • The rotate draft gains a transform route carrying the full transform list; the frame draws it and puts the
    element's transform back on a cancel.
  • Both directions validate the transform text at the boundary (isTransformList: CSS functions of numbers and
    units, only transform functions and calc/var/min/max/clamp, at most 512 characters), since a sealed frame's text can reach the saved source.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

fails without the fix: gsapMoveSealedPreview.test.ts "turns a sealed layer its stylesheet rotates from the angle it
shows" (starts at 0, want 30), editingGestureStart.test.ts "reads the CSS turn a layer GSAP does not turn shows, for
a stand-in that cannot", editingDraft.test.ts "turns inside a translating transform and puts the transform back on a
cancel", editingAgent.test.ts "draws a turn inside a translating transform through the port", and
previewElements.test.ts "takes a frame's CSS turn only with plain transform text".

Core and Studio typecheck, and every test file beside a changed file passes.

Before

The same rotate drag on a layer centred by a stylesheet transform: translate(-50%, -50%) and turned 30 degrees, in a
sealed preview, after the drop: the turn starts from 0 and lands short.

Before: sealed rotate lands short

After

It lands where the unsealed preview puts it.

After: sealed rotate lands where unsealed does

…ngle its stylesheet shows

A sealed preview's stand-in carries only inline styles, so a rotate on a layer whose stylesheet sets its turn or a
centring transform started from 0 and turned about the wrong point. The frame's gesture-start answer now reports the
CSS turn (angle and where to draw it) from computed style, read by the same code Studio used, moved to
@hyperframes/core/runtime/css-rotation. The rotate draft gains a transform route, which the frame's validator now
accepts; both sides check the transform text before it can reach the saved source.

@vanceingalls vanceingalls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested at 9056d18, for one hole in the boundary check. The rest looks right.

Blocker: isTransformList (core/src/runtime/editingPort.ts:484) lets through text that corrupts the saved HTML. The charset [\w\s().,%+\-*/] allows /*, and nothing checks that parentheses balance. A sealed frame's before/after go through isRotationTarget → turnedTransform() → applyCssRotation's inline-style patch → patchInlineStyleInTag. splitInlineStyleDeclarations (studio/src/utils/sourcePatcher.ts:57) doesn't split on ; while parenDepth > 0. So a hostile frame sending translate(1px (unclosed), or translate(1px) /*, makes the element's other inline declarations get swallowed into the transform value and saved that way.

The attribute writer escapes, and ", ', ;, braces, <, :, \ are all excluded, so there's no attribute or script breakout. This is about a stranger's film being able to corrupt the person's file.

Fix: reject /* and */, and require balanced parentheses (depth never below 0, and 0 at the end). Add one test for each, next to the existing url(/;/length cases.

Checked and fine:

  • angle/share are finite and bounded through isTurn/MAX_DRAFT_DEG.
  • A bad cssRotation falls back to the stand-in read.
  • var(--x) as written text is harmless.
  • Cancel restores rotate and transform (DRAWN now includes transform).
  • drawPreviewDraft acts only on registered stand-ins, so the unsealed path is unchanged.
  • The css-rotation export is consistent in package.json and package-subpaths.json, with no import cycle.

Nits:

  • lastRuleTransform calls element.matches(rule.selectorText) with no try/catch. Now that it runs in the frame at gesture start, one bad selector fails the whole reply.
  • gestureStart reads the CSS rotation for every gesture kind, not only rotate.
  • Importing positionEdits for splitTopLevelWhitespace pulls analytics into the frame bundle.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 63 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

Unstable (1)

  • seqplainkeys-none-pct-r0-root-z100: tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

…list

A character allowlist let 'translate(1px' and '/*' through, so a frame could close the saved inline transform early
and swallow the element's other inline styles into it. isTransformList now folds innermost known calls until none
are left and accepts only what folds away: known function names, balanced parentheses, no comments.

@vanceingalls vanceingalls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at 6586b51, CI green. This clears my changes-requested on 9056d18. isTransformList now parses instead of matching a charset. It folds the innermost known call (a TRANSFORM_CALL name whose arguments hold no parentheses) to a token until nothing changes, and passes only when nothing but those tokens and whitespace is left. It rejects /* up front.

So:

  • an unclosed translate(1px never folds, and fails;
  • a stray ) or anything outside a call is left over, and fails;
  • scale(2) /* x fails;
  • nested translateX(calc(10px + var(--a))) still folds and passes.

The new cases are in both editingAgent.test.ts and previewElements.test.ts, including scale(2));color:red. Saved inline styles can no longer be swallowed into a transform value.

The earlier nits still stand. They're optional:

  • wrap lastRuleTransform's element.matches in a try/catch;
  • read the CSS rotation at gesture start for rotate only.

…stylesheet

# Conflicts:
#	packages/core/src/runtime/editingGestureStart.ts
#	packages/studio/src/components/editor/previewGestureStartRead.test.ts
#	packages/studio/src/components/editor/previewGestureStartRead.ts
#	packages/studio/src/player/lib/previewElements.ts

@vanceingalls vanceingalls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approved at 6ead6c9. This head is a merge of main, which brings in #8467, #8454 and #8471. The PR's own patch against its new merge-base matches the 6586b51 I approved line for line. The conflicts with #8467 in editingGestureStart.ts, previewGestureStartRead.ts and previewElements.ts were resolved by keeping both sides: #8467's draft imports and gesture-start fields alongside this PR's readCssRotationStart, isRotationTarget and isCssRotation. The parsing isTransformList is unchanged.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 22, 2026
@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 22, 2026

@vanceingalls vanceingalls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approved at cd2d62e. This head only merges main (#8451, #8458, #8452) into the PR, and the PR's own patch against its merge-base is identical to the 6ead6c9 I approved.

…stylesheet

# Conflicts:
#	packages/core/src/runtime/editingPort.ts

@vanceingalls vanceingalls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approved at 5b63445. This head is a merge of main (#8489, #8475, #8477) only, and the PR's own patch against its merge-base is identical to the cd2d62e I approved.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 039eca4 Nov 22, 2026
101 checks passed
@miguel-heygen
miguel-heygen deleted the oncall/sealed-rotate-stylesheet branch November 22, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants